import wx
import wx.xrc

class XrcHandler(wx.xrc.XmlResourceHandler):

    extra_styles = [
        "CP_DEFAULT_STYLE",
    ]

    def __init__(self):
        wx.xrc.XmlResourceHandler.__init__(self)
        self.AddWindowStyles()
        for style in self.extra_styles:
            self.AddStyle("wx%s" % style, getattr(wx, style))

    def CanHandle(self,node):
        return self.IsOfClass(node, 'CollapsiblePane') or \
            self.IsOfClass(node, 'wxCollapsiblePane')

    def DoCreateResource(self):
        assert self.GetInstance() is None
        _res = wx.CollapsiblePane(
            self.GetParentAsWindow(),
            self.GetID(),
            self.GetText('label'),
            pos=self.GetPosition(),
            size=self.GetSize(),
            style=self.GetStyle()
        )
        self.SetupWindow(_res)
        _node = self.GetNode()
        _child = _node.GetChildren()
        _panel = None
        while _child:
            if self.IsOfClass(_child, 'panewindow'):
                _panel = _child
                break
            _child = _node.GetNext()
        assert _panel
        # assuming 'panewindow' has only one child -- actual contents
        self.CreateResFromNode(_panel.GetChildren(), _res.GetPane())
        self.SetupWindow(_res)
        return _res

# vim: set sts=4 sw=4 et :
